//
//  JiebangVC.m
//  SSC
//
//  Created by 红沙尘 on 17/7/11.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "JiebangVC.h"
#import "JiebangCell.h"
@interface JiebangVC ()<UITableViewDelegate,UITableViewDataSource,JiebangCellDelegate>
{
    __weak IBOutlet UITableView *myTableView;
    NSMutableArray *dataArray;
}
@end

@implementation JiebangVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"解绑银行卡"];
    
    [myTableView registerNib:[UINib nibWithNibName:@"JiebangCell" bundle:nil]
      forCellReuseIdentifier:@"JiebangCell"];
    myTableView.rowHeight = 128;
    myTableView.estimatedRowHeight = 128;
    
    dataArray = [[NSMutableArray alloc] init];
    
    myTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        WeakSelf;
        [weakSelf cardListRequest];
    }];
    [myTableView.mj_header beginRefreshing];
}

- (void)cardListRequest {
    [SSCRequest cardListSuccess:^(NSDictionary *responseObject) {
        [myTableView.mj_header endRefreshing];
        NSArray *data = [NSString safeArray:responseObject[@"data"]];
        
        [dataArray removeAllObjects];
        [dataArray addObjectsFromArray:data];
        [myTableView reloadData];
        
    } fail:^(NSError *error) {
        [myTableView.mj_header endRefreshing];
    }];
}

#pragma mark - JiebangCellDelegate

- (void)jiebangWithDict:(NSDictionary *)dict {
    
    [LoadingView show];
    
    [SSCRequest jiebangWithId:[NSString safeString:dict[@"id"]]
                      success:^(NSDictionary *responseObject) {
                          [LoadingView diss];
                          [myTableView.mj_header beginRefreshing];
                      } fail:^(NSError *error) {
                          [LoadingView diss];
                      }];
}

#pragma mark - tableVeiw

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    JiebangCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JiebangCell"];
    cell.jDelegate = self;
    [cell loadWithDict:dataArray[indexPath.row]];
    
    return cell;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
